package com.web;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.LeaveDTO;
import model.UserDTO;
import bizlogic.LeaveManager;

/**
 * @Thiri
 * Servlet implementation class SubordinateServlet
 */
@WebServlet("/SubordinateServlet")
public class SubordinateServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SubordinateServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doProcess(request,response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doProcess(request,response);
	}
	
	protected void doProcess(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//java.util.ArrayList<UserDTO> id = request.getParameter("id");
	    System.out.println("search"); 
		UserDTO us =(UserDTO)request.getSession().getAttribute("user");
		String id = us.getId().toString();
	     
	     System.out.println(id);
		
		LeaveManager lm=new LeaveManager();
		ArrayList<LeaveDTO> data = lm.findAllSubordinateByManagerId(id);
		
	    request.setAttribute("mgrId", data);
		RequestDispatcher rd = request.getRequestDispatcher("SubordinateLeaveHistory.jsp");
		rd.forward(request, response);
		
		
		
		}

}
